package edu.grupo4.appcomedores;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrador on 31/08/13.
 */
public class Producto extends Activity {

    // Array of options --> ArrayAdapter --> ListView

    //List view: {views: da_items.xml}
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.actividad_producto);

        comentarioView();
        registerClickCallback();
    }
    private void comentarioView(){
        //Create list of items
        String[] myItems = {"Articulo1","Articulo2","Articulo3"};
        //Build Adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                this,               //Context for the activity.
                R.layout.da_item,   //Layout to use (create)
                myItems);           //Items to be displayed

        //Configure the list view.
        ListView list =(ListView)findViewById(R.id.listViewProducto);
        list.setAdapter(adapter);
    }
    private void registerClickCallback(){
        ListView list =(ListView)findViewById(R.id.listViewProducto);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> paret, View viewClicked, int position, long id) {
                TextView textView = (TextView)viewClicked;
                String message ="Su Producto es: " + textView.getText().toString();
                //Presenta el comentario
                Toast.makeText(Producto.this, message, Toast.LENGTH_LONG).show();
            }
        });


    }
}
